package com.hst.capacity.infra.persistence.jpa.setting.price;


import com.hst.capacity.domain.model.entity.setting.price.RailwayStationPriceEntity;
import com.hst.capacity.domain.model.response.setting.price.RailwayStationSearchVO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface RailwayStationPriceRepository extends JpaRepository<RailwayStationPriceEntity, String> {

    @Query("select new com.hst.capacity.domain.model.response.setting.price.RailwayStationSearchVO(p,r) from RailwayStationPriceEntity p left join RailwayEntity r on p.idStation=r.idStation where p.idFranchisee=:idFranchisee")
    Page<RailwayStationSearchVO> findByIdFranchisee(String idFranchisee, PageRequest pageRequest);

    /**
     * 通过地区查找站点价格
     * @param regionCode
     * @return
     */
    @Query("select o " +
            "from RailwayStationPriceEntity o " +
            "inner join FranchiseeEntity a on a.idFranchisee = o.idFranchisee " +
            "where a.regionCode =:regionCode ")
    List<RailwayStationPriceEntity> findByRegionCode(@Param("regionCode")String regionCode);

    /**
     * 通过地区查找站点价格
     * @param idStation
     * @return
     */
    @Query("select o " +
            "from RailwayStationPriceEntity o " +
            "where o.idFranchisee =:idFranchisee " +
            "and o.idStation =:idStation " +
            "and o.idServiceType =:idServiceType " +
            "and o.idVehicleType =:idVehicleType " )
    RailwayStationPriceEntity findByIdStation(@Param("idFranchisee")String idFranchisee, @Param("idStation")String idStation, @Param("idServiceType")int idServiceType, @Param("idVehicleType")int idVehicleType);


    /**
     * 通过地区查找站点价格
     * @param idStation
     * @return
     */
    @Query("select o " +
            "from RailwayStationPriceEntity o " +
            "where o.idFranchisee =:idFranchisee " +
            "and o.idStation =:idStation " +
            "and o.idServiceType =:idServiceType ")
    List<RailwayStationPriceEntity> findByIdStation(@Param("idFranchisee")String idFranchisee, @Param("idStation")String idStation, @Param("idServiceType")int idServiceType);

}